var wc = new Js2WordCloud(document.getElementById('mywordcloud'));
var sect1;
 function getnum() {
 	return parseInt(Math.random() * 100)
 }

 function load(name) {
 	let xhr = new XMLHttpRequest(),
 		okStatus = document.location.protocol === "file:" ? 0 : 200;
 	xhr.open('GET', name, false);
 	xhr.overrideMimeType("text/html;charset=utf-8"); //默认为utf-8
 	xhr.send(null);
 	return xhr.status === okStatus ? xhr.responseText : null;
 }
 var option = getoption("");
 wc.setOption(option)
 window.onresize = function() {
 	wc.resize()
 }

 function getoption(filename) {
 	let text; //读取文件构造数组
 	if (filename == null || filename.length == 0) {
 		text = load('../data/wordcloud2.txt');
 	} else {
 		text = load("../data/" + filename);
 	}

 	var arr1 = text.split("\n");
 	var arr2 = new Array();
 	var arr3 = new Array();
 	for (var i = 0; i < arr1.length - 1; i++) {
 		arr2 = arr1[i].split(",");
 		arr3[i] = new Array();
 		arr3[i][0] = arr2[0];
 		arr3[i][1] = parseInt(arr2[1]);
 	}
 	var color = ["#000000", "#444444", "#888888", "#534121", "#ff0000", "#fc666d", "#f6ca75", "#beb80f", "#afaa28",
 		"#c602cd", "#f65afc",
 		"#a152ca", "#404d92", "#0000ff", "#80f4fe", "#02c9db", "#7e71fe", "#86fb7a", "#108f03", "#155c19"
 	];
 	console.log(arr1);
 	var option = {
 		list: arr3,
 		color(word, weight, fontSize, distance, theta) { //自定义颜色
 			if (weight > 100) {
 				return color[19];
 			}
 			return color[Math.floor((weight - 1) / 5)];
 		},
 		shape: 'circle',
 		ellipticity: 1,
 		minRotation: -1.57080,
 		maxRotation: 5.57080,
 		rotateRatio: .2,
 		fontSizeFactor: 1, // 当词云值相差太大，可设置此值进字体行大小微调，默认0.1
 		maxFontSize: 34, // 最大fontSize，用来控制weightFactor，默认60
 		minFontSize: 10,
 		gridSize: 12,
 		ratationSteps: 1,
 		rotationRation: .5,
 		shuffle: 1,
 		//shape: 'circle', //还可以选择‘cardioid’（苹果形或心形），‘star’（星形），默认是‘circle’，即圆形,‘diamond’（钻石），‘triangle-forward’（三角形），‘triangle’（三角形），‘pentagon’（五边形）
 		// cardioid: 'diamond'					 
 	}
	 $("#num1").text(arr3.length);
 	return option;
 }
 $("#select-word2").change(function() {
 	 sect1 = parseInt( this.options[this.options.selectedIndex].value);
 	 
 }); 
 
 $("#select-word3").change(function() {
 	var id = parseInt( this.options[this.options.selectedIndex].value);
 	var filename;
	if(sect1!=null)
	{
	   id=10;
	  }
 	switch (id) {
 		case 0: filename = "wordcloud3.txt"; break;
 		case 1: filename = "wordcloud3_1.txt";break;
 		case 2: filename = "wordcloud3_2.txt";break;
 		case 3: filename = "wordcloud3_3.txt";break;
 		case 4: filename = "wordcloud3_4.txt";break;
 		case 5: filename = "wordcloud3_5.txt";break;
		case 6: filename = "wordcloud3_6.txt";break;
		case 7: filename = "wordcloud3_7.txt";break;
		case 8: filename = "wordcloud3_8.txt";break;
		case 9: filename = "wordcloud3_9.txt";break;
		default:filename = "wordcloud2.txt";break;
		
 	}
 	var option = getoption(filename);
 	wc.setOption(option)
 });

 // function show_sub()
 // {
 //  alert("jjj")
 //  var  id=this.options[this.options.selectedIndex].value;
 // }
